﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tierless.Framework.EntityTypes;

namespace Tierless.Framework.Server.UnitTests
{
	// EmployeePhone { EmployeeID } references Employee { ID }
	// EmployeeDepartment { EmployeeID } references Employee { ID }
	// Department { ParentID } references Department { ID }
	// EmployeeDepartment { DepartmentID } references Department { ID }

	[EntityConstraints("Employee")]
	static class EmployeeConstraints
	{
		public static void Register(EntityType entityType)
		{
			// EmployeePhone { EmployeeID } references Employee { ID }
			entityType.References.Add
			(
				new EntityReference("TFK_EmployeePhone_Employee_Child")
				{
					SourceEntityTypeName = "EmployeePhone",
					SourceColumnNames = new string[] { "EmployeeID" },
					TargetEntityTypeName = "Employee",
					TargetColumnNames = new string[] { "ID" },
					Kind = ReferenceKind.Child
				}
			);
			
			// EmployeeDepartment { EmployeeID } references Employee { ID }
			entityType.References.Add
			(
				new EntityReference("TFK_EmployeeDepartment_Employee_Child")
				{
					SourceEntityTypeName = "EmployeeDepartment",
					SourceColumnNames = new string[] { "EmployeeID" },
					TargetEntityTypeName = "Employee",
					TargetColumnNames = new string[] { "ID" },
					Kind = ReferenceKind.Child
				}
			);
		}
	}
	
	[EntityConstraints("EmployeePhone")]
	static class EmployeePhoneConstraints
	{
		public static void Register(EntityType entityType)
		{
			// EmployeePhone { EmployeeID } references Employee { ID }
			entityType.References.Add
			(
				new EntityReference("TFK_EmployeePhone_Employee_Lookup")
				{
					SourceEntityTypeName = "EmployeePhone",
					SourceColumnNames = new string[] { "EmployeeID" },
					TargetEntityTypeName = "Employee",
					TargetColumnNames = new string[] { "ID" },
					Kind = ReferenceKind.Lookup
				}
			);
		}
	}

	[EntityConstraints("Department")]
	static class DepartmentConstraints
	{
		public static void Register(EntityType entityType)
		{
			// Department { ParentID } references Department { ID }
			entityType.References.Add
			(
				new EntityReference("TFK_Department_Department_Child")
				{
					SourceEntityTypeName = "Department",
					SourceColumnNames = new string[] { "ParentID" },
					TargetEntityTypeName = "Department",
					TargetColumnNames = new string[] { "ID" },
					Kind = ReferenceKind.Child
				}
			);

			entityType.References.Add
			(
				new EntityReference("TFK_Department_Department_Lookup")
				{
					SourceEntityTypeName = "Department",
					SourceColumnNames = new string[] { "ParentID" },
					TargetEntityTypeName = "Department",
					TargetColumnNames = new string[] { "ID" },
					Kind = ReferenceKind.Lookup
				}
			);

			// EmployeeDepartment { DepartmentID } references Department { ID }
			entityType.References.Add
			(
				new EntityReference("TFK_EmployeeDepartment_Department_Child")
				{
					SourceEntityTypeName = "EmployeeDepartment",
					SourceColumnNames = new string[] { "DepartmentID" },
					TargetEntityTypeName = "Department",
					TargetColumnNames = new string[] { "ID" },
					Kind = ReferenceKind.Child
				}
			);
		}
	}

	[EntityConstraints("EmployeeDepartment")]
	static class EmployeeDepartmentConstraints
	{
		public static void Register(EntityType entityType)
		{
			// EmployeeDepartment { EmployeeID } references Employee { ID }
			entityType.References.Add
			(
				new EntityReference("TFK_EmployeeDepartment_Employee_Lookup")
				{
					SourceEntityTypeName = "EmployeeDepartment",
					SourceColumnNames = new string[] { "EmployeeID" },
					TargetEntityTypeName = "Employee",
					TargetColumnNames = new string[] { "ID" },
					Kind = ReferenceKind.Lookup
				}
			);

			// EmployeeDepartment { DepartmentID } references Department { ID }
			entityType.References.Add
			(
				new EntityReference("TFK_EmployeeDepartment_Department_Lookup")
				{
					SourceEntityTypeName = "EmployeeDepartment",
					SourceColumnNames = new string[] { "DepartmentID" },
					TargetEntityTypeName = "Department",
					TargetColumnNames = new string[] { "ID" },
					Kind = ReferenceKind.Lookup
				}
			);
		}
	}
}
